import React from 'react'
import '../css/Borard.css'
import eventEmitter from '../event'

class Borard extends React.Component {
	constructor(props) {
		super(props)
		this.state = {
			messages: [],
		}
	}

	componentDidMount() {
		eventEmitter.addListener('sendmessage', (item) => {
			// console.log(item)
			this.state.messages.push(item)
			this.setState({
				messages: this.state.messages,
			})
		})
	}

	render() {
		return (
			<div className="main">
				{this.state.messages.map((item,index) => {
					return (
						<div className="content" key={index}>
							<h3>{item.content}</h3>
							<h3>{item.date}</h3>
						</div>
					)
				})}
			</div>
		)
	}
}

export default Borard
